FILE (GLOB SCRIPTS "*.py")

MACRO(ADD_SCRIPTS TARGET FILES)
  ADD_CUSTOM_TARGET(${TARGET} ALL)
  SET(_FILES ${FILES} ${ARGN})
  FOREACH(FILENAME ${_FILES})
    SET(SRC "${FILENAME}")
    GET_FILENAME_COMPONENT(DSTFILE ${FILENAME} NAME_WE)
    SET(DST "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${DSTFILE}")
    ADD_CUSTOM_COMMAND(
      TARGET ${TARGET}
      COMMAND ${CMAKE_COMMAND} -E copy ${SRC} ${DST}
      COMMENT "Copying ${SRC}")
    SET(MAKE_CLEAN_FILES ${MAKE_CLEAN_FILES} ${DST})
    SET(INSTALL_BINS ${INSTALL_BINS} ${DST})
  ENDFOREACH(FILENAME)
  SET_PROPERTY(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "${MAKE_CLEAN_FILES}")
  INSTALL(PROGRAMS ${INSTALL_BINS} DESTINATION bin)
ENDMACRO(ADD_SCRIPTS)

ADD_SCRIPTS(${TARGET_SCRIPTS} ${SCRIPTS})
